package com.proback.repository;

import com.proback.entity.BookData;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface BookDataRepository extends JpaRepository<BookData, Integer> {

    List<BookData> findByUserId(Integer userId);

    // 根据用户 ID 和年份查询记账数据
    @Query("SELECT bd FROM BookData bd WHERE bd.user.id = :userId AND FUNCTION('YEAR', bd.bookDate) = :year")
    List<BookData> findByUserIdAndBookDateYear(Integer userId, int year);

    // 根据用户 ID 和年月查询记账数据
    @Query("SELECT bd FROM BookData bd WHERE bd.user.id = :userId AND FUNCTION('YEAR', bd.bookDate) = :year AND FUNCTION('MONTH', bd.bookDate) = :month")
    List<BookData> findByUserIdAndBookDateYearAndBookDateMonth(Integer userId, int year, int month);
}
